import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Jiange
 * @create 2021-08-10-23:05
 */
public class Server {
    public static void server() throws IOException {
        ServerSocket server = new ServerSocket(8899);
        Socket socket = server.accept();
        InputStream inputStream = socket.getInputStream();
        while (true){
            byte[] bytes = inputStream.readAllBytes();
            String message = new String(bytes,"utf-8");
            System.out.println(message);

            socket.shutdownInput();

            OutputStream outputStream = socket.getOutputStream();
            if(message.equals("88")){
                socket.close();
                server.close();
                inputStream.close();
                outputStream.close();
                System.exit(0);
            }

            outputStream.write(bytes);
        }
    }

    public static void main(String[] args) throws IOException {
        server();
    }
}
